package cheme.ProcessModel.Cmds;

import cheme.ProcessModel.IChild;
import cheme.ProcessModel.IParent;

public class AddCmd extends ChemeCommand
{
	private IChild child;
	private IParent parent;
	
	private int index = -1;

	public AddCmd(IChild child, IParent parent)
	{
		this(child, parent, -1);
	}

	public AddCmd(IChild child, IParent parent, int index)
	{
		super(parent, "Add command");
		
		this.child = child;
		this.parent = parent;
		this.index = index;
	}

	@Override
	protected void primExecute()
	{
		if (index < 0)
		{
			parent.add(child);
		}
		else
		{
			parent.add(child, index);
		}
	}

	@Override
	protected void primUndo()
	{
		parent.remove(child);
	}
}